<?php
/********************
 *@param function:管理員組管理 model
 *@param datetime 2011-6-7
 *@param author solgh
 ********************/
class Admins_group_mdl extends CI_model{
  //操作的表.
  const TAB_NAME='clickrcms_admin_group';

  function __construct(){
    parent::__construct();
    log_message('debug','admins_group_mdl Model class Initialized');
  }

  /****
   *查詢所admins_group,加分页
   *$data :查询参数.
   */
  public function get_admins_group($data=array()){
    if(!empty($data)){
      extract($data);
      isset($field) && isset($sort)?$this->db->order_by($field.' '.$sort):$this->db->order_by('add_time ASC');
      isset($limits) && isset($offset)?$this->db->limit($limits,$offset):'';
      isset($name) && !empty($name)?$this->db->like('name',$name):'';
      return $this->db->get(self::TAB_NAME);
    }
  }
  /****
   * 統計所有的admins_group
   */
  public function totle_admins_group($data=array()){
    if(!empty($data)){
      extract($data);
      isset($name) && !empty($name)?$this->db->like('name',$name):'';
      return $this->db->count_all_results(self::TAB_NAME);
    }else{
      return $this->db->count_all(self::TAB_NAME);
    }
  }

  /****
   *查詢admins_group,無緩存模式
   *$data :查询参数.
   */
  public function get_core_admins_group($data=array()){
    if(!empty($data)){
      extract($data);
      $this->db->order_by('sort_order ASC');
      isset($limits) && isset($offset)?$this->db->limit($limits,$offset):'';
      $this->db->cache_off();
      $query=$this->db->get(self::TAB_NAME);
      $this->db->cache_on();
      return $query;
    }
  }
  /*****
   * 根據ID來刪除
   */
  public function delete_admins_group($admins_group_id=0){
    if(!empty($admins_group_id)){
      $this->db->where("id",$admins_group_id);
      $this->db->delete(self::TAB_NAME);
      return ($this->db->affected_rows()>0)?true:false;
    }
  }

  /****
   *根据ID来查询得到一个信息.
   *$id :要查詢的ID
   */
  public function get_admins_group_by_id($id){
    $data=array();
    $this->db->where('id',$id);
    $get_result=$this->db->get(self::TAB_NAME);
    if($get_result->num_rows()>0)
    {
      $data=$get_result->row_array();
    }
    $get_result->free_result();
    return $data;
  }

  /***
   * 修改一個admins_group
   * @param array $data
   * @param int  $c_id
   * return :受影响的行数
   */
  public function edit_admins_group($data=array(),$b_id=0){
    if(!empty($data) && !empty($b_id)){
      $this->db->where('id',$b_id);
      $this->db->update(self::TAB_NAME,$data);
      return ($this->db->affected_rows()>0)?true:false;
    }
  }
  /***
   * 新增一個 admins_group
   */
  public function add_admins_group($data=array()){
    if(!empty($data)){
      $this->db->insert(self::TAB_NAME,$data);
      return ($this->db->affected_rows()>0)?true:false;
    }
  }
}